package com.dianping.cat.home.storage.transform;

import com.dianping.cat.home.storage.IEntity;
import com.dianping.cat.home.storage.IVisitor;
import com.dianping.cat.home.storage.entity.Link;
import com.dianping.cat.home.storage.entity.Storage;
import com.dianping.cat.home.storage.entity.StorageGroup;
import com.dianping.cat.home.storage.entity.StorageGroupConfig;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private StorageGroupConfig m_storageGroupConfig;


  public DefaultMerger() {}

  public DefaultMerger(StorageGroupConfig storageGroupConfig) {
/*  22 */     this.m_storageGroupConfig = storageGroupConfig;
/*  23 */     this.m_objs.push(storageGroupConfig);
  }


/*  27 */   public StorageGroupConfig getStorageGroupConfig() { return this.m_storageGroupConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }

  protected void mergeLink(Link to, Link from) {
/*  41 */     to.mergeAttributes(from);
/*  42 */     to.getPars().addAll(from.getPars());
  }


/*  46 */   protected void mergeStorage(Storage to, Storage from) { to.mergeAttributes(from); }



/*  50 */   protected void mergeStorageGroup(StorageGroup to, StorageGroup from) { to.mergeAttributes(from); }



/*  54 */   protected void mergeStorageGroupConfig(StorageGroupConfig to, StorageGroupConfig from) { to.mergeAttributes(from); }



  public void visitLink(Link from) {
/*  59 */     Link to = (Link)this.m_objs.peek();

/*  61 */     mergeLink(to, from);
/*  62 */     visitLinkChildren(to, from);
  }


  protected void visitLinkChildren(Link to, Link from) {}


  public void visitStorage(Storage from) {
/*  70 */     Storage to = (Storage)this.m_objs.peek();

/*  72 */     mergeStorage(to, from);
/*  73 */     visitStorageChildren(to, from);
  }


  protected void visitStorageChildren(Storage to, Storage from) {}


  public void visitStorageGroup(StorageGroup from) {
/*  81 */     StorageGroup to = (StorageGroup)this.m_objs.peek();

/*  83 */     mergeStorageGroup(to, from);
/*  84 */     visitStorageGroupChildren(to, from);
  }

  protected void visitStorageGroupChildren(StorageGroup to, StorageGroup from) {
/*  88 */     if (from.getLink() != null) {
/*  89 */       Link target = to.getLink();

/*  91 */       if (target == null) {
/*  92 */         target = new Link();
/*  93 */         to.setLink(target);
      }

/*  96 */       this.m_objs.push(target);
/*  97 */       from.getLink().accept(this);
/*  98 */       this.m_objs.pop();
    }

/* 101 */     for (Storage source : from.getStorages().values()) {
/* 102 */       Storage target = to.findStorage(source.getId());

/* 104 */       if (target == null) {
/* 105 */         target = new Storage(source.getId());
/* 106 */         to.addStorage(target);
      }

/* 109 */       this.m_objs.push(target);
/* 110 */       source.accept(this);
/* 111 */       this.m_objs.pop();
    }
  }


  public void visitStorageGroupConfig(StorageGroupConfig from) {
/* 117 */     StorageGroupConfig to = (StorageGroupConfig)this.m_objs.peek();

/* 119 */     mergeStorageGroupConfig(to, from);
/* 120 */     visitStorageGroupConfigChildren(to, from);
  }

  protected void visitStorageGroupConfigChildren(StorageGroupConfig to, StorageGroupConfig from) {
/* 124 */     for (StorageGroup source : from.getStorageGroups().values()) {
/* 125 */       StorageGroup target = to.findStorageGroup(source.getId());

/* 127 */       if (target == null) {
/* 128 */         target = new StorageGroup(source.getId());
/* 129 */         to.addStorageGroup(target);
      }

/* 132 */       this.m_objs.push(target);
/* 133 */       source.accept(this);
/* 134 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/storage/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */